<?
if($_GET['page'] == 'account')
{
	$uid = $_SESSION['uid']; 
	$query = "select * from tbl_reporting_personnel where rp_id= $uid";
	$result = mysql_query($query);
	
	$cquery = "select * from  tbl_companies";
	$cresult = mysql_query($cquery);

	if (mysql_num_rows($result)!= 1) {$error = 1;} 
	else { 
		$row = mysql_fetch_row($result);
		$rp_first_name = $_POST['rp_first_name'];
		$rp_last_name = $_POST['rp_last_name'];
		$c_nickname = $_POST['c_nickname'];
		$rp_phone_number = $_POST['rp_phone_number'];
		$rp_phone_ext = $_POST['rp_phone_ext'];
		$rp_fax_number = $_POST['rp_fax_number'];
		$rp_email = $_POST['rp_email'];
		$rp_user_name = $_POST['rp_user_name'];
		if($_POST['submit']=='submit'){
			$update_query = "UPDATE tbl_reporting_personnel SET rp_phone_number='$rp_phone_number'," .
			"rp_phone_ext='$rp_phone_ext',rp_fax_number='$rp_fax_number',rp_email='$rp_email' WHERE rp_id = '".$uid."' LIMIT 1;";
			$update_result = mysql_query($update_query);                  
		    if (!$update_result) {die('Query error: '. mysql_error());}
		    else if($update_result){?>
		    	<script>
				$(document).ready(function(){
					 $("#success").text("Updated Successfully!").show();
					 return false;
				});
				</script>
		    <?}
		    	$query = "select * from tbl_reporting_personnel where rp_id= $uid";
				$result = mysql_query($query);
			 	$row = mysql_fetch_row($result);
		}else if($_POST['change_password'] == 'Change Password'){
			extract($_POST);
			if(($rp_password == $rp_confirm_password) && ($rp_password != '') && ($rp_confirm_password != ''))
			{
				$password = md5($rp_password);
				$update_password_query = "UPDATE tbl_reporting_personnel SET rp_password='$password' WHERE rp_id = '".$uid."' LIMIT 1;";
				$update_password = mysql_query($update_password_query);
				if($update_password){?>
				<script>
				$(document).ready(function(){
					 $("#success").text("Your Password has been Updated Successfully!").show();
					 return false;
				});
				</script>
				<?}
			}
			else{?>
				<script>
				$(document).ready(function(){
					 $("#error").text("Passwords do not match!").show();
					 return false;
				});
				</script>
			<?} 
		}
	}
}
?>
<script>
$(document).ready(function(){
   $("#personal_info").validate();
});
</script>

<h1>Account Information</h1>
<span id='error'></span><span id='success'></span>
<div id="accordion">
<h3><a href="#">Personnel Account Information</a></h3>
<div>
<form action="index.php?page=account" method="post" id="personal_info">
<table cellpadding="4">
	<tr>
		<td><label><strong>First Name :</strong></label></td>
		<td><span style="color:#0762A3"><? echo $row[2];?></span></td>
	</tr>
	<tr>
		<td><label><strong>Last Name :</strong></label></td>
		<td><span style="color:#0762A3"><? echo $row[3];?></span></td>
	</tr>
	<tr>
		<td><label><strong>Company Name :</strong></label></td>
		<? if($_SESSION['user_level'] == 4){?>	
		<td>
		<select name="c_nickname">
		<? while($crow = mysql_fetch_array($cresult)){?>
		<option value=<?=$crow['c_nickname'];?>
		<? if($row[1] == $crow['c_nickname']){ echo 'selected="selected"'; } else {} ?>
		><?=$crow['c_nickname'];?></option>
		<?}?>
		</select>
		</td>
		<?}else{?>
		<td>
			<span style="color:#0762A3"><? echo $row[1];?></span>
		</td>
		<?}?>
	</tr>
	<tr>
		<td><label><strong>Phone Number :</strong></label></td>
		<td><input type="text" name="rp_phone_number" value="<? echo $row[4];?>" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Extension :</strong></label></td>
		<td><input type="text" name="rp_phone_ext" value="<? echo $row[5];?>" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Fax Number :</strong></label></td>
		<td><input type="text" name="rp_fax_number" value="<? echo $row[6];?>" class="number"/></td>
	</tr>
	<tr>
		<td><label><strong>Email :</strong></label></td>
		<td><input type="text" name="rp_email" value="<? echo $row[7];?>" class="email"/></td>
	</tr>
	<? if($_SESSION['user_level'] == 4){?>	
	<tr>
		<td><label><strong>Username :</strong></label></td>
		<td><input type="text" name="rp_user_name" value="<? echo $row[8];?>" class="required"/></td>
	</tr>
	<? }else{?>
	<tr>
		<td><label><strong>Username :</strong></label></td>
		<td><span style="color:#0762A3"><? echo $row[8];?></span></td>
	</tr>
	<? }?>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" value="submit" name="submit" /></td>
	</tr>
</table>
</form>
</div>
<h3><a href="#">Change Password</a></h3>
<div>
	<form action="index.php?page=account" method="post" id="change_pass">
	<table>
		<tr>
			<td><label><strong>Password :</strong></label></td>
			<td><input type="password" name="rp_password" /></td>
		</tr>
		<tr>
			<td><label><strong>Confirm Password :</strong></label></td>
			<td><input type="password" name="rp_confirm_password" /></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input type="submit" value="Change Password" name="change_password" /></td>
		</tr>
	</table>
	</form>
</div>
</div>


